package com.hs.controller;

import com.hs.VO.LessonPO;
import com.hs.VO.LessonStudentVO;
import com.hs.config.R;
import com.hs.entity.ClassLessonIssue;
import com.hs.service.ClassLessonIssueService;
import com.hs.service.ClassLessonService;
import com.hs.service.LessonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;
@RequestMapping("common")
@Controller
public class CommonController {
    @Autowired
    LessonService lessonService;
    @Autowired
    ClassLessonIssueService classLessonIssueService;
    @Autowired
    ClassLessonService classLessonService;

    /**
     *  课程往期期数数据
     * @param session
     * @param model
     * @param lesson classLessonId
     * @return
     */
    @RequestMapping("/lessonOutIssues")
    public String lessonProcessInfo(HttpSession session, Model model, LessonPO lesson){
        if(lesson == null || lesson.getClassLessonId() == null){
            return "error";
        }
        session.setAttribute("user",session.getAttribute("user"));
        model.addAttribute("user",session.getAttribute("user"));
        model.addAttribute("classLessonId",lesson.getClassLessonId());
        lesson.setId(lesson.getClassLessonId());

        if(lesson == null || lesson.getId() == null){
            return "error";
        }
        LessonStudentVO lessonInfoVO = lessonService.selectStudentLessonInfo(lesson);
        model.addAttribute("lesson",lessonInfoVO);
        return "common/lesson_out_issues";
    }

    @RequestMapping("/lessonOutIssuesData")
    @ResponseBody
    public R lessonOutIssuesData(HttpSession session, Model model, LessonPO lesson){
        if(lesson == null || lesson.getClassLessonId() == null){
            return R.FAILURE("请传参",null);
        }
        ClassLessonIssue classLessonIssue = new ClassLessonIssue();
        classLessonIssue.setClassLessonId(lesson.getClassLessonId());
        List<ClassLessonIssue> lessonIssueList = classLessonIssueService.selectByCondition(classLessonIssue);

        return R.SUCCESS("", lessonIssueList);
    }
}
